function Account(balance, password) {
  this.balance = balance;
  this.password = password;
  this.wrongTimes = 0;
}
const output = x => console.log(x);
Account.prototype.withdraw = function (amount, input) {
  return checkPassword.call(this, input, fn.bind(this), amount);
  function fn(amount) {
    if (this.balance >= amount) {
      this.balance -= amount;
      return output(this.balance);
    }
    return output('not enough money');
  }
};
Account.prototype.deposit = function (amount) {
  this.balance += amount;
  return output(this.balance);
};
function checkPassword(input, fn, ...args) {
  if (this.wrongTimes >= 6) return output('call the cops');
  if (input === this.password) {
    this.wrongTimes = 0;
    return fn(...args);
  }
  this.wongTimes += 1;
  return output('wrong');
}

//工行账户
function ICBC(balance, password) {
  Account.call(this, balance, password);
}
ICBC.prototype = Object.create(Account.prototype);
ICBC.prototype.withdraw = function (amount, input) {
  return checkPassword.call(this, input, fn.bind(this), amount);
  //每次取现收1元手续费
  function fn(amount) {
    if (this.balance >= amount) {
      this.balance -= amount + 1;
      return output(this.balance);
    }
    return output('not enough money');
  }
};

//农行账户
function ABC(balance, password) {
  Account.call(this, balance, password);
}
ABC.prototype = Object.create(Account.prototype);
//存钱输密码
ABC.prototype.deposit = function (amount, input) {
  return checkPassword.call(this, input, fn.bind(this), amount);
  function fn(amount) {
    this.balance += amount;
    return output(this.balance);
  }
};

const accICBC01 = new ICBC(100, '123456');
accICBC01.withdraw(100, '12345');
accICBC01.withdraw(90, '123456');
accICBC01.deposit(200);

const accABC01 = new ABC(200, '234567');
accABC01.withdraw(100, '23456');
accABC01.withdraw(120, '234567');
accABC01.deposit(300, '234567');
